<!--评分对话框-->
<script setup lang="ts">


import { getCurrentInstance, reactive, ref } from "vue";
import { FormInstance } from "element-plus";
import { reqScoring } from "@/api/credit/peasants/score";
import { reqBaseData } from "@/api/type";
import { reqBankInfoById } from "@/api/credit/loans/bank";
import { LoansBank } from "@/api/credit/loans/bank/type";


const title = ref("添加银行");
const dialogVisible = ref(false);

const ruleForm: LoansBank = reactive({
  bankId: undefined,
  bankName: undefined,
  bankAddress: undefined,
  bankIcon: undefined,
  bankNum: undefined,
  status: "0",
  remark: undefined // 其他说明
});

let $emit = defineEmits(["getList"]);
const { proxy }: any = getCurrentInstance();


// 对外暴露
const show = async (bankId: number) => {
  dialogVisible.value = false;
  title.value = "添加银行"
  // 判断有没有id进行修改或者添加
  if (bankId != null) {
    title.value = "修改银行"
    // 获取对应要修改的银行信息
    await reqBankInfoById(bankId).then((req) => {
      if(req.code == 200) {
        Object.keys(ruleForm).forEach((key) => {
          ruleForm[key] = req.data[key]
        })
      }else {
        // 获取信息失败
        proxy.$modal.msgError("获取信息失败，请稍后再试！")
        return
      }
    }).catch((e) => {

      proxy.$modal.msgError("获取银行数据失败，请稍后再试！");
      return;
    });
  }
  // 否则直接进行添加

  // 打开对话框
  setTimeout(() => {
    dialogVisible.value = true;
  }, 500);
};

// 关闭对话框后的回调
const close = () => {
  Object.keys(ruleForm).forEach((key) => {
    if(key == "status") ruleForm[key] = '0'
    else ruleForm[key] = undefined;
  });
};

const rules = ref({
  gamble: [{
    required: true,
    message: "本人及家庭成员是否有赌博行为不能为空",
    trigger: "change"
  }],
  drugRelated: [{
    required: true,
    message: "本人及家庭成员是否有涉毒行为不能为空",
    trigger: "change"
  }],
  whoring: [{
    required: true,
    message: "本人及家庭成员是否有嫖娼行为不能为空",
    trigger: "change"
  }],
  black: [{
    required: true,
    message: "本人及家庭成员是否有涉黑行为不能为空",
    trigger: "change"
  }],
  privateLending: [{
    required: true,
    message: "本人及家庭成员是否有参有民间借贷不能为空",
    trigger: "change"
  }],
  onlineLoan: [{
    required: true,
    message: "本人及家庭成员是否有网贷不能为空",
    trigger: "change"
  }],
  loveCountry: [{
    required: true,
    message: "爱国爱党、遵纪守法不能为空",
    trigger: "change"
  }],
  aggresively: [{
    required: true,
    message: "积极上进、产业发展意志强烈不能为空",
    trigger: "change"
  }],
  familyRship: [{
    required: true,
    message: "家庭关系、邻里关系和谐不能为空",
    trigger: "change"
  }],
  inteConcept: [{
    required: true,
    message: "具有诚信观念、说话算话不能为空",
    trigger: "change"
  }],
  remark: [{
    required: true,
    message: "请输入其他说明",
    trigger: "blur"
  }]
});

// 提交
const handleSubmit = async () => {
/*  await reqScoring(from).then((req: reqBaseData) => {
    if (req.code == 200) {
      proxy.$modal.msgSuccess("评议成功！");
      dialogVisible.value = false;
      $emit("getList");
    } else {
      proxy.$modal.msgError("评议失败，请稍后重试！");
    }
  }).catch(() => {
  });*/
};


defineExpose({
  show
});
</script>


<template>
  <el-dialog width="600px" v-model="dialogVisible" @close="close">
    <template #title>
      <span class="el-dialog__title">{{ title }}</span>
    </template>
    <el-form ref="ruleFormRef1" :model="ruleForm" :rules="rules" size="default" label-width="100px" label-position="left">
      <el-form-item label="银行名" prop="bankName">
        <el-input v-model="ruleForm.bankName" maxlength="20" show-word-limit clearable placeholder="请输入银行名" />
      </el-form-item>
      <el-form-item label="主行地址" prop="bankAddress">
        <el-input v-model="ruleForm.bankAddress" maxlength="50" show-word-limit clearable placeholder="请输入主行地址" />
      </el-form-item>
      <el-form-item label="银行图标" prop="bankIcon">
        <!--上传图标        -->

      </el-form-item>
      <el-form-item label="银行编号" prop="bankNum">
        <el-input v-model="ruleForm.bankAddress" maxlength="50" show-word-limit clearable placeholder="请输入主行地址" />
      </el-form-item>

      <el-form-item label="管理人" prop="phonenumber">
        <el-input v-model="ruleForm.bankIcon" placeholder="请输入手机号" maxlength="11" show-word-limit />
      </el-form-item>

      <el-form-item label="用户状态" prop="status">
        <el-radio-group v-model="ruleForm.status">
          <el-radio
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.value"
          >
            {{ dict.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="备注" prop="remark">
        <el-input v-model="ruleForm.remark" type="textarea" placeholder="请输入用户备注" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="success" @click="handleSubmit">确定</el-button>
        <el-button type="warning" @click="dialogVisible = false">取消</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts">
export default {
  dicts: ["base_yes_no", "pea_score_grade"]
};
</script>

<style scoped lang="scss">
@import "../index";
</style>
